<template>
  <WorthHeader>
    网易严选
  </WorthHeader>
  <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
    <van-swipe-item v-for="(item,index) in newBannerData" :key="index">
      <img :src="item" alt="" class="bannerImg">
    </van-swipe-item>
    <template #indicator="{ active, total }">
    <div class="custom-indicator">{{ active + 1 }}/{{ total }}</div>
    </template>
  </van-swipe>

  <div class="banner">
    <div class="left">
      <span class="leftTop">限时特惠</span>
      <div class="leftBottom">
        <span class="yuan">￥</span>
        <span class="price">{{detailsData?.banner.processBanner.priceInfo.basicPrice}}</span>
        <div class="leftLeft">
          <span class="hand">到手￥</span>
          <span class="handPrice">{{detailsData?.banner.processBanner.priceInfo.finalPrice?.price}}</span>
        </div>
      </div>
    </div>
    <div class="right">
       <img class="logoUrl" src="https://yanxuan.nosdn.127.net/static-union/16716956421db06a.png" alt="">
    </div>
  </div>

  <div class="goodsName">
    <div class="baseInfo">
      <div class="info">
        <div class="name">
          {{ detailsData?.name }}
        </div>
        <div class="simpleBrandInfo">
          <img :src="detailsData?.simpleBrandInfo.logoUrl" alt="" class="img">
          <span class="idawong">{{ detailsData?.simpleBrandInfo.title }}</span>
        </div>
        <div class="desc">推荐理由</div>
        <div class="descItem">
          <ul>
            <li v-for="(list,index) in detailsData?.recommendReason" :key="index">
              <div class="descDiv">
                <div class="descIcon">{{index+1}}</div>
              </div>
              <div class="descText">{{ list}}</div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
  <div class="rcmdBanner" v-if="detailsData?.adBanners">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" style="height: 100px;">
      <van-swipe-item v-for="ban in detailsData?.adBanners">
        <img class="bannerImg" :src="ban.picUrl" alt="">
      </van-swipe-item>
    </van-swipe>
  </div>

  <div class="down">
      <div class="erji"><van-icon name="service-o" class="icon" size="30" /></div>
        <div class="buy">立即购买</div>
          <div class="bottomcart">加入购物车</div>
      </div>

</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  name: "Detail",
});
</script>
<script lang="ts" setup>
import { useRoute } from 'vue-router'
import { computed, onMounted, ref, toRaw } from 'vue'
import { getDetailsApi } from '@/api/search'
import type { detailsData } from '@/api/modules/search'


const route = useRoute()
const id = ref<string>('')
const detailsData = ref<detailsData>()
onMounted(async () => {
  id.value = route.query.id as string
  const res = await getDetailsApi(id.value)
  detailsData.value = res.item
  
  
  
})

const newBannerData = computed(() => {
  const data = detailsData.value?.itemDetail
  const res: string[] = []
  for (let index in data) {
    //@ts-ignore
    res.push(data[index])
  }
  res.splice(0, 1)
  res.splice(res.length - 1, 1)
  return res
})


</script>
<style lang="less" scoped>
.bannerImg {
  height: 375px;
}
.custom-indicator {
    position: absolute;
    right: 15px;
    bottom: 15px;
    padding: 2px 5px;
    font-size: 12px;
    background: white;
    border-radius: 3px;
  }
.goodsName {
  width: 375px;
  height: 180px;
  box-sizing: border-box;
  display: flex;
  padding: 13px 0 18px 15px;

  .baseInfo {
    display: flex;
    height: 100px;

    .info {
      display: flex;
      flex-direction: column;
      height: 100px;
      justify-content: space-between;

      .name {
        width: 259px;
        height: 48px;
        font-size: 16px;
        font-weight: 900;
      }

      .simpleBrandInfo {
        display: flex;
        align-items: center;

        .img {
          width: 14px;
          height: 14px;
        }

        .idawong {
          font-size: 10px;
          color: #7f7f7f;
        }
      }

      .desc {
        font-size: 10px;
        color: #7f7f7f;
      }

      .descItem{
        width: 345px;
        height: 60px;
        background-color: #fafafa;
        margin: 6px 0 0 0;
        padding: 5px 0;
        border: 1px solid #f0f0f0;

        ul li{
          height: 18px;
          display: flex;
          margin-bottom: 5px;
        }
        .descDiv{
          width: 14px;
          height: 14px;
          margin-right: 10px;
          .descIcon{
            width: 100%;
            height: 100%;
            border: 1px solid #dd1a21;
            border-radius: 50%;
            text-align: center;
            line-height: 12px;
            font-size: 2px;
            color: #dd1a21;
            font-family: PingFang SC;
            font-weight: 700;
            vertical-align: middle;
          }
        }

       

        .descText{
          height: 16px;
          line-height: 16px;
          font-size: 10px;
          vertical-align: middle;
        }
      }
    }

    .title {
      margin-left: 10px;
      font-size: 14px;
      display: flex;
      align-items: flex-end;
    }
  }
}

.rcmdBanner {
  margin-top: 10px;
  height: 100px;
  .bannerImg{
    width: 375px;
    height: 100px;
  }
}

.my-swipe .van-swipe-item {
  color: #fff;
  height: 375px;
  font-size: 20px;
  text-align: center;
}

.banner {
  height: 74px;
  background-color: red;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;

  .left {
    .leftTop {
      color: #fff;
      font-size: 12px;
    }

    .leftBottom {
      display: flex;
      align-items: center;

      .yuan {
        font-size: 16px;
        color: #fff;
        font-weight: 900;
      }

      .price {
        color: #fff;
        font-weight: 900;
      }

      .leftLeft {
        margin-left: 5px;
        padding: 0 5px;
        box-sizing: border-box;
        border-radius: 20px;
        background-color: #fff;
        display: flex;
        align-items: center;

        .hand {
          text-align: center;
          color: red;
          font-size: 12px;
          font-weight: 900;
        }

        .handPrice {
          color: red;
          font-size: 16px;
          font-weight: 900;
        }
      }


    }
  }

  .right {
    display: flex;
    font-size: 20px;
    align-items: center;
    justify-content: center;
    color: white;

    .logoUrl{
      width: 75px;
      height: 40px;
    }
  }

 
}
.down{
    width: 375px;
    height: 52px;
    display: flex;
    font-size: 16px;
    z-index: 1;
    position: sticky;
    bottom: 0px;
}
.erji{
    width: 78px;
    height: 50px;
    background-color: white;
    justify-content: center;
    display: flex;
    align-items: center;
    border: #c7c7c7 1px solid;
}
.buy {
    width: 150px;
    height: 50px;
    text-align: center;
    line-height: 51px;
    border: #c7c7c7 1px solid;
    border-left: none;
    background-color: white;
}
.bottomcart {
    width: 150px;
    height: 52px;
    text-align: center;
    line-height: 52px;
    // border: #c7c7c7 1px solid;
    color: white;
    background-color: #fa1e32;
}
</style>
